import { ENTITY } from "../../../../constData/_";
import { DelApprovePolicy, GetApprove, GetProjectManagement, GetUserInfo, PostApprove } from "../../../../constData/requestFun/_teseRequest";
import { GetUserInfoFiled } from "../../../../constData/requestFun/_utils";
import compact from 'lodash/compact'
import uniq from 'lodash/uniq'

const GetName = (id: string) => {
  return new Promise((resolve) => {
    GetUserInfo({
      userId: id,
      fileds: null
    }, (res) => {
      resolve({ id, name: GetUserInfoFiled(res, 'name') })
    })
  })
}

Page({
  data: {
    allFiledNameList: [
      {
        label: '时长', value: 'SumTime', group: [ENTITY['请假'], ENTITY['出差']]
      },
      {
        label: '金额', value: 'TotalAmount', group: [ENTITY['采购申请'], ENTITY['采购确认']]
      },
      {
        label: '金额', value: 'InvoiceAmount', group: [ENTITY['开票功能']]
      },
      {
        label: '金额', value: 'ReceiptAmount', group: [ENTITY['开收据功能']]
      },
      {
        label: '金额', value: 'Amount', group: [ENTITY['报销功能'], ENTITY['付款功能'],ENTITY['流片付款'],]
      },
      {
        label: '类型', value: 'TypeExpense', group: [ENTITY['报销功能']]
      },
      {
        label: '类型', value: 'PaymentType', group: [ENTITY['付款功能']]
      },
      {
        label: '预计金额', value: 'TotalAmount', group: [ENTITY['流片付款']]
      },
    ],
    filedName: [],
    entityType: [],
    pickEntity: ENTITY['请假'] as string,

    conditionType: [
      { label: '大于', value: 'G' },
      { label: '等于', value: 'E' },
      { label: '小于', value: 'L' },
      { label: '大于等于', value: 'GE' },
      { label: '小于等于', value: 'LE' },
    ],
    //审核信息处理
    approvalList: [] as {
      id: number,
      conditions: { id: number, filedName: '', t: '', value: '' }[],
      approverIds: { userId: '', name: '' }[],
      copyIds: { userId: '', name: '' }[],
      entityName: string,
    }[],

    SelectedValue: '',
    LeaveInfo: [],//请假数据
    EvectionInfo: [],//出差数据
    PurchasedConfirmationInfo: [],//采购申请确认数据
    PurchasRequisitInfo: [],//采购申请数据
    SealInfo: [],//用印申请数据
    MeetronmInfo: [],//会议室申请数据
    ContractInfo: [],//合同管理
    TopicInfo: [],//议题申请
    MeetMinutesInfo: [],//会议纪要
    SalaryInfo:[],//薪资审批
    InvoicInfo: [],//开票数据
    IssueReceiptInfo: [],//开收据数据
    ExpenseAccountInfo: [],//报销数据
    PaymentFunctionInfo: [],//付款管理
    ProjectArchivingInfo: [],//项目管理
    TapoutBusinessInfo: [],//流片付款
    OrderManagementInfo: [],//订单管理
    ConsumablesManagementInfo: [],//耗材管理
    BasicApplication: [
      { text: '请假审核', value: 'LeaveInfo' },
      { text: '出差审核', value: 'EvectionInfo' },
    ],
    IntegratedAdministrationType: [
      { text: '采购申请', value: 'PurchasRequisitInfo' },
      { text: '采购确认', value: 'PurchasedConfirmationInfo' },
      { text: '用印申请', value: 'SealInfo' },
      { text: '议题申请', value: 'TopicInfo' },
      { text: '会议纪要', value: 'MeetMinutesInfo' },
      { text: '合同审批', value: 'ContractInfo' },
      { text: '薪资审批', value: 'SalaryInfo' },
    ],
    FinancialManagementType: [
      { text: '开票申请', value: 'InvoicInfo' },
      { text: '开收据申请', value: 'IssueReceiptInfo' },
      { text: '报销申请', value: 'ExpenseAccountInfo' },
      { text: '付款申请', value: 'PaymentFunctionInfo' },
    ],
    ProjectManagementType: [
      { text: '项目管理', value: 'ProjectArchivingInfo' },
    ],
    TapeOutPaymentsType: [
      { text: '流片付款', value: 'TapoutBusinessInfo' },
    ],
    LaboratoryType: [
      { text: '设备试验', value: '0000' },
      { text: '订单审批', value: 'OrderManagementInfo' },
      { text: '耗材审批', value: 'ConsumablesManagementInfo' },
    ],
    showLeave: true,
    showEvection: true,
    showPurchasedConfirmation: true,
    showPurchasRequisit: true,
    showSeal: true,
    showMeetronm: true,
    showTopic: true,
    showContract: true,
    showMeetMinutes: true,
    showSalary: true,
    showInvoic: true,
    showIssueReceipt: true,
    showExpenseAccount: true,
    showPaymentFunction: true,
    showProjectArchiving: true,
    showTapoutBusiness: true,
    showOrderManagement: true,
    showConsumablesManagement: true,
  },
  DelPolicyld(e) {
    const id = e.currentTarget.dataset.id;
    const entityName = e.currentTarget.dataset.entityName
    console.log('eeee',e);
    
    DelApprovePolicy(id, (res) => {
      //更新数据
      if (entityName === 'ELeave') {
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'ELeave')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions,
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)

            })
            return data
          })
        }).then(res => {
          this.setData({ LeaveInfo: res })
        })
      }
      else if (entityName === 'EBussinessTrip') {
        //出差申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EBussinessTrip')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ EvectionInfo: res })
        })
      }
      else if (entityName === 'EPurchaseRequest') {
        //采购申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EPurchaseRequest')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ PurchasRequisitInfo: res })
        })
      }
      else if (entityName === 'EProcurementConfirmation') {
        //采购确认
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EProcurementConfirmation')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ PurchasedConfirmationInfo: res })
        })
      }
      else if (entityName === 'EUseSeal') {
        //用印申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EUseSeal')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ SealInfo: res })
        })
      }
      else if (entityName === 'ETopic') {
        //议题申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'ETopic')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ TopicInfo: res })
        })
      }
      else if (entityName === 'EMeetingMinutes') {
        //会议纪要
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EMeetingMinutes')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ MeetMinutesInfo: res })
        })
      }
      else if (entityName === 'EContractManagement') {
        //合同管理
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EContractManagement')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ ContractInfo: res })
        })
      }
      else if (entityName === 'ESalaryInfo') {
        //薪资审批
        console.log('sssssss');
        
        new Promise((resolve) => {
          GetApprove((res: any) => {
            console.log('res',res);
            
            resolve(res.data)
          }, 'ESalaryInfo')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ SalaryInfo: res })
        })
      }
      else if (entityName === 'EInvoicing') {
        //开票申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EInvoicing')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ InvoicInfo: res })
        })
      }
      else if (entityName === 'EIssueReceipts') {
        //开收据申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EIssueReceipts')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ IssueReceiptInfo: res })
        })
      }
      else if (entityName === 'EReimbursement') {
        //报销申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EReimbursement')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          console.log('res',res);
          
          this.setData({ ExpenseAccountInfo: res })
        })
      }
      else if (entityName === 'EPayment') {
        //付款申请
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EPayment')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ PaymentFunctionInfo: res })
        })
      }
      else if (entityName === 'EProjectManagement') {
        //项目管理
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EProjectManagement')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ ProjectArchivingInfo: res })
        })
      }
      else if (entityName === 'EChipPayment') {
        //流片
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EChipPayment')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ TapoutBusinessInfo: res })
        })
      }
      else if (entityName === 'EOrder') {
        //订单管理
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EOrder')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ OrderManagementInfo: res })
        })
      }
      else if (entityName === 'EConsumableManagement') {
        //耗材管理
        new Promise((resolve) => {
          GetApprove((res: any) => {
            resolve(res.data)
          }, 'EConsumableLog')
        }).then((res: any[]) => {
          if (!res || res === null || res === undefined) throw new Error("数据为空")
          const data = [], ids = []
          res.forEach(item => {
            const cacheData = {}
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            cacheData['approverIds'] = compact(item.approverIds.split(' '))!
            cacheData['copyIds'] = compact(item.copyIds.split(' '))!
            cacheData['conditions'] = item.conditions
            data.push(cacheData)
            ids.push(...compact(item.approverIds.split(' '))!)
            ids.push(...compact(item.copyIds.split(' '))!)
          })
          ids.splice(0, ids.length, ...uniq(ids))
          return [data, ids]
        }).then(res => {
          return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
            const data = []
            res[0].forEach(item => {
              const cacheData = {
                conditions: item.conditions
              }
              cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              data.push(cacheData)
            })
            return data
          })
        }).then(res => {
          this.setData({ ConsumablesManagementInfo: res })
        })
      }
      my.alert({
        title: '删除成功',
      });
    }, (fail) => {
      my.alert({
        title: '删除失败',
      });
    })
  },
  BasicApplicationChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    if (value === 'LeaveInfo') {
      //请假申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'ELeave')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions,
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })    
          return data
        })
      }).then(res => {
        this.setData({ LeaveInfo: res })
      })

    } else if (value === 'EvectionInfo') {
      //出差申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EBusinessTrip')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ EvectionInfo: res })
      })
    }
  },
  IntegratedAdministrationChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    if (value === 'PurchasRequisitInfo') {
      //采购申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EPurchaseRequest')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ PurchasRequisitInfo: res })
      })
    }
    else if (value === 'PurchasedConfirmationInfo') {
      //采购确认
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EProcurementConfirmation')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ PurchasedConfirmationInfo: res })
      })
    }
    else if (value === 'SealInfo') {
      //用印申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EUseSeal')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ SealInfo: res })
      })
    }
    else if (value === 'TopicInfo') {
      //议题申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'ETopic')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ TopicInfo: res })
      })
    }
    else if (value === 'MeetMinutesInfo') {
      //会议纪要
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EMeetingMinutes')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ MeetMinutesInfo: res })
      })
    }
    else if (value === 'ContractInfo') {
      //合同管理
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EContractManagement')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ ContractInfo: res })
      })
    }
    else if (value === 'SalaryInfo') {
      //薪资审批
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'ESalaryInfo')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ SalaryInfo: res })
      })
    }
  },
  FinancialManagementChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    if (value === 'InvoicInfo') {
      //开票申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EInvoicing')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ InvoicInfo: res })
      })
    } else if (value === 'IssueReceiptInfo') {
      //开收据申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EIssueReceipts')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ IssueReceiptInfo: res })
      })
    }
    else if (value === 'ExpenseAccountInfo') {
      //报销申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EReimbursement')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ ExpenseAccountInfo: res })
      })
    }
    else if (value === 'PaymentFunctionInfo') {
      //付款申请
      new Promise((resolve) => {
        GetApprove((res: any) => {
          resolve(res.data)
        }, 'EPayment')
      }).then((res: any[]) => {
        if (!res || res === null || res === undefined) throw new Error("数据为空")
        const data = [], ids = []
        res.forEach(item => {
          const cacheData = {}
          cacheData['id'] = item.id
          cacheData['entityName'] = item.entityName
          cacheData['approverIds'] = compact(item.approverIds.split(' '))!
          cacheData['copyIds'] = compact(item.copyIds.split(' '))!
          cacheData['conditions'] = item.conditions
          data.push(cacheData)
          ids.push(...compact(item.approverIds.split(' '))!)
          ids.push(...compact(item.copyIds.split(' '))!)
        })
        ids.splice(0, ids.length, ...uniq(ids))
        return [data, ids]
      }).then(res => {
        return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
          const data = []
          res[0].forEach(item => {
            const cacheData = {
              conditions: item.conditions
            }
            cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
            cacheData['id'] = item.id
            cacheData['entityName'] = item.entityName
            data.push(cacheData)
          })
          return data
        })
      }).then(res => {
        this.setData({ PaymentFunctionInfo: res })
      })
    }
  },
  ProjectManagementChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'ProjectArchivingInfo') {
          //项目管理
          new Promise((resolve) => {
            GetApprove((res: any) => {
              resolve(res.data)
            }, 'EProjectManagement')
          }).then((res: any[]) => {
            if (!res || res === null || res === undefined) throw new Error("数据为空")
            const data = [], ids = []
            res.forEach(item => {
              const cacheData = {}
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              cacheData['approverIds'] = compact(item.approverIds.split(' '))!
              cacheData['copyIds'] = compact(item.copyIds.split(' '))!
              cacheData['conditions'] = item.conditions
              data.push(cacheData)
              ids.push(...compact(item.approverIds.split(' '))!)
              ids.push(...compact(item.copyIds.split(' '))!)
            })
            ids.splice(0, ids.length, ...uniq(ids))
            return [data, ids]
          }).then(res => {
            return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
              const data = []
              res[0].forEach(item => {
                const cacheData = {
                  conditions: item.conditions
                }
                cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['id'] = item.id
                cacheData['entityName'] = item.entityName
                data.push(cacheData)
              })
              return data
            })
          }).then(res => {
            this.setData({ ProjectArchivingInfo: res })
          })
        }
      }
    })
  },
  TapeOutPaymentsChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'TapoutBusinessInfo') {
          //流片
          new Promise((resolve) => {
            GetApprove((res: any) => {
              resolve(res.data)
            }, 'EChipPayment')
          }).then((res: any[]) => {
            if (!res || res === null || res === undefined) throw new Error("数据为空")
            const data = [], ids = []
            res.forEach(item => {
              const cacheData = {}
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              cacheData['approverIds'] = compact(item.approverIds.split(' '))!
              cacheData['copyIds'] = compact(item.copyIds.split(' '))!
              cacheData['conditions'] = item.conditions
              data.push(cacheData)
              ids.push(...compact(item.approverIds.split(' '))!)
              ids.push(...compact(item.copyIds.split(' '))!)
            })
            ids.splice(0, ids.length, ...uniq(ids))
            return [data, ids]
          }).then(res => {
            return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
              const data = []
              res[0].forEach(item => {
                const cacheData = {
                  conditions: item.conditions
                }
                cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['id'] = item.id
                cacheData['entityName'] = item.entityName
                data.push(cacheData)
              })
              return data
            })
          }).then(res => {
            this.setData({ TapoutBusinessInfo: res })
          })
        }
      }
    })
  },
  TapeLaboratoryChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'OrderManagementInfo') {
          //订单管理
          new Promise((resolve) => {
            GetApprove((res: any) => {
              resolve(res.data)
            }, 'EOrder')
          }).then((res: any[]) => {
            if (!res || res === null || res === undefined) throw new Error("数据为空")
            const data = [], ids = []
            res.forEach(item => {
              const cacheData = {}
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              cacheData['approverIds'] = compact(item.approverIds.split(' '))!
              cacheData['copyIds'] = compact(item.copyIds.split(' '))!
              cacheData['conditions'] = item.conditions
              data.push(cacheData)
              ids.push(...compact(item.approverIds.split(' '))!)
              ids.push(...compact(item.copyIds.split(' '))!)
            })
            ids.splice(0, ids.length, ...uniq(ids))
            return [data, ids]
          }).then(res => {
            return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
              const data = []
              res[0].forEach(item => {
                const cacheData = {
                  conditions: item.conditions
                }
                cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['id'] = item.id
                cacheData['entityName'] = item.entityName
                data.push(cacheData)
              })
              return data
            })
          }).then(res => {
            this.setData({ OrderManagementInfo: res })
          })
        }
        else if (value === 'ConsumablesManagementInfo') {
          //耗材管理
          new Promise((resolve) => {
            GetApprove((res: any) => {
              resolve(res.data)
            }, 'EConsumableLog')
          }).then((res: any[]) => {
            if (!res || res === null || res === undefined) throw new Error("数据为空")
            const data = [], ids = []
            res.forEach(item => {
              const cacheData = {}
              cacheData['id'] = item.id
              cacheData['entityName'] = item.entityName
              cacheData['approverIds'] = compact(item.approverIds.split(' '))!
              cacheData['copyIds'] = compact(item.copyIds.split(' '))!
              cacheData['conditions'] = item.conditions
              data.push(cacheData)
              ids.push(...compact(item.approverIds.split(' '))!)
              ids.push(...compact(item.copyIds.split(' '))!)
            })
            ids.splice(0, ids.length, ...uniq(ids))
            return [data, ids]
          }).then(res => {
            return Promise.all(res[1].map(it => GetName(it))).then((r: any[]) => {
              const data = []
              res[0].forEach(item => {
                const cacheData = {
                  conditions: item.conditions
                }
                cacheData['approverIds'] = item.approverIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['copyIds'] = item.copyIds.map(id => r.filter(rIndex => rIndex.id === id)[0].name)
                cacheData['id'] = item.id
                cacheData['entityName'] = item.entityName
                data.push(cacheData)
              })
              return data
            })
          }).then(res => {
            this.setData({ ConsumablesManagementInfo: res })
          })
        }
      }
    })
  },
  onLoad() {
    this.setData({
      entityType: Object.keys(ENTITY).map(key => ({ label: key, value: ENTITY[key] }))
    })
  },
  show(e) {
    const item = e.target.dataset.item
    this.setData({ [item]: !this.data[item] })
  },
  onC_FiledNameOk(v, rawE, e) {
    const data = e ? e.target.dataset : rawE.target.dataset
    this.setData({
      approvalList: this.data.approvalList.map(it => {
        if (it.id == data.id) {
          it.conditions = it.conditions.map(c => {
            if (c.id == data.cid) {
              c[data.filedName] = v
            }
            return c
          })
        }
        return it
      }),
    })
  },
  onTypePick(e) {
    const filedName = this.data.allFiledNameList
      .filter(it => it.group.indexOf(e) !== -1)
    this.setData({
      pickEntity: e, filedName,
      approvalList:[]
    })
    console.log('pickEntity'),this.data.pickEntity;
    
  },
  onApprovalAdd() {
    this.setData({
      approvalList: [
        ...this.data.approvalList,
        {
          id: Math.random() * 99999,
          conditions: [],
          approverIds: [],
          copyIds: [],
          entityName: this.data.pickEntity
        }
      ]
    })
    console.log('approvalList',this.data.approvalList);
    
  },
  onApproveConditionsAdd(e) {
    const data = e.target.dataset
    this.setData({
      approvalList: this.data.approvalList.map(it => {
        if (it.id == data.id) {
          it.conditions = [...it.conditions, {
            filedName: '',
            value: '',
            t: '',
            id: Math.random() * 99999
          }]
        }
        return it;
      })
    })
  },
  onUserAdd(e) {
    const data = e.target.dataset
    // @ts-ignore
    my.complexChoose({
      title: "选择人", //标题
      multiple: true, //是否多选
      maxUsers: 1000, //最大可选人数
      responseUserOnly: true, //返回人，或者返回人和部门
      success: (res) => {
        this.setData({
          approvalList: this.data.approvalList.map(it => {
            if (it.id == data.id) {
              (it[data.filedName] as any[]).push(...res.users)
            }
            return it
          }),
        })
      }
    })
  },
  onCopyAdd(e) {
    const data = e.target.dataset
    // @ts-ignore
    my.complexChoose({
      title: "选择人", //标题
      multiple: true, //是否多选
      maxUsers: 1000, //最大可选人数
      responseUserOnly: true, //返回人，或者返回人和部门
      success: (res) => {
        this.setData({
          approvalList: this.data.approvalList.map(it => {
            if (it.id == data.id) {
              (it[data.filedName] as any[]).push(...res.users)
            }
            return it
          }),
        })
      }
    })

  },
  deleteCondition(e){
    // console.log('eeee',e);
    const id=e.currentTarget.dataset.id
    const cid=e.currentTarget.dataset.cid
    this.setData({
      approvalList: this.data.approvalList.map(it => {
        if (it.id ==id) {
          it.conditions=it.conditions.filter(it=>it.id!==cid)
        }
        return it
      })
    })
  },
  deleteUser(e) {
    const data = e.target.dataset
    this.setData({
      approvalList: this.data.approvalList.map(it => {
        if (it.id == data.id) {
          it[data.filedName] = it[data.filedName].filter(a => a.userId != data.userId)
        }
        return it
      })
    })
  },
  OnSubmit(e) {
    const id = e.currentTarget.dataset.id
    const matchingRecords = this.data.approvalList.filter(item => item.id === id)
    const convertedApprovalList = convertApproverIds(matchingRecords);
    PostApprove(JSON.stringify(convertedApprovalList[0]),
      (res) => {
        my.alert({
          title: '提交成功',
        });

      },
      (err) => {
        my.alert({
          title: '提交成功1',
        });
      })

  },
});
function convertApproverIds(approvalList) {
  return approvalList.map(item => {
    // 提取 approverIds 中的 userId 并拼接成字符串  
    const approverIdsStr = item.approverIds.map(approver => approver.userId).join(' ');
    // 提取 copyIds 中的 userId 并拼接成字符串  
    const copyIdsStr = item.copyIds.map(copy => copy.userId).join(' ');
    // 移除原始的 approverIds 数组，并添加转换后的字符串  
    const { id, conditions, approverIds, copyIds, ...rest } = item;
    // 删除 conditions 数组中每个元素的 id 属性  
    const newConditions = conditions.map(condition => {
      const { id, ...conditionRest } = condition;
      return conditionRest;
    });
    return {
      ...rest,
      approverIds: approverIdsStr, // 使用字符串替换原来的数组
      copyIds: copyIdsStr, // 使用字符串替换原来的 copyIds 数组 
      conditions: newConditions
    };

  });
}

